package com.zhang.hadoop.flink.test;

import org.apache.commons.lang3.StringUtils;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.directive.Directive;
import org.apache.velocity.runtime.parser.node.Node;

import java.io.IOException;
import java.io.Writer;
import java.util.Objects;

/**
 * @author zhang yufei
 * @date 2022/11/17 15:13
 **/
public class UserNameFunction extends Directive {

    @Override
    public String getName() {
        return "userNameFunction";
    }

    @Override
    public int getType() {
        return LINE;
    }

    @Override
    public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
        //Object value = node.jjtGetChild(0).value(context);
        //if(Objects.nonNull(value) && StringUtils.isNotBlank(value.toString())){
        //    String userName=value.toString();
        //    userName=userName.replaceAll("\\先生|女士","同学");
        //    writer.write(userName);
        //}
        return true;
    }
}
